package atom.core2.j2ee.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.commons.lang.RandomStringUtils;

import atom.core2.j2ee.util.SessionManager;

/**
 * @author aps-zmc
 *
 */
public class TokenTag extends SimpleTagSupport {
	private static final long serialVersionUID = 1L;

	

	public void doTag() throws JspException, IOException {
		String deferContent = "";
		String random = RandomStringUtils.randomNumeric(10);
		HttpServletRequest request = (HttpServletRequest) ((PageContext) this.getJspContext()).getRequest();
		String tokenKey = (String) request.getAttribute(SessionManager.TOKEN_KEY);
		deferContent="<input type=\"hidden\" name=\""+SessionManager.TOKEN_KEY+"\" value=\""+random+"\"/>";

		
		this.getJspContext().getOut().write(deferContent);
	}


}
